//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.chris.serve;

import com.alibaba.fastjson.JSONObject;
import com.chris.impl.contentImpl;
import com.chris.utils.DbConnection;
import com.chris.utils.JsonProcess;
import com.chris.utils.LogUtil;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet({"/registerPaper"})
public class registerPaper extends HttpServlet {
    private final contentImpl dao = new contentImpl();

    public registerPaper() {
    }

    public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        JSONObject read = JsonProcess.read(req.getInputStream());
        PrintWriter writer = resp.getWriter();
        DbConnection.begin();
        try {
            int journal_id = (Integer)read.get("journal_id");
            String paper_title = (String)read.get("paper_title");
            String author = (String)read.get("author");
            String keyword = (String)read.get("keyword");
            String page_number = (String)read.get("page_number");
            long size = this.dao.getSize();
            if (size > 0L) {
                this.dao.insert(journal_id, size + 1L, paper_title, author, keyword, page_number);
                writer.print(JsonProcess.respSuccess("添加成功", null));
                DbConnection.commit();
            }
            else DbConnection.rollBack();
        } catch (Exception var12) {
            DbConnection.rollBack();
            LogUtil.log("参数错误",var12);
            writer.print(JsonProcess.respError("参数错误"));
        }

    }

    public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.addHeader("Access-Control-Allow-Headers", "*");
        resp.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT");
    }
}
